package cn.wolfcode.crm.domain;

import cn.wolfcode.crm.util.JsonResult;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@ToString
public class CustomerTraceHistory {

    private Long id;

    @DateTimeFormat(pattern = "yyyy-MM-dd")

    private Date traceTime;//跟进时间
    private String traceDetails;//跟进内容
    private SystemDictionaryItem traceType;//跟进方式
    private Integer traceResult;//跟进结果
    private String remark;//备注
    private Customer customer;//跟进客户
    private Employee inputUser;//录入人
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date inputTime;//录入时间
    private Integer type;//客户类型


    public String getTypeName(){
        switch (type){
            case Customer.STATUS_POTENTIAL:return "潜在客户";
            default:return"正式客户";
        }

    }

    public String getTraceName(){
        String traceName="";
        if(traceResult==1){
            traceName="差";
        }
        else if(traceResult==2){
            traceName="中";
        }else{
            traceName="优";
        }
        return traceName;
    }

    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("customerId",customer.getId());
        map.put("customerName",customer.getName());
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        map.put("traceTime",format.format(traceTime));
        map.put("traceDetails",traceDetails);
        map.put("traceTypeId",traceType.getId());
        map.put("traceResult",traceResult);
        map.put("remark",remark);
        map.put("type",type);

        ObjectMapper mapper = new ObjectMapper();
        try {
            String json = mapper.writeValueAsString(map);
            return json;
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }


}